"use strict";
const Base = require("../base");
const LANG = require("../../language"); // 插件语言库
// 内存shell模块
class MemoryShell extends Base {
  precheck() {
    if (this.shelltype == "jsp") {
      return true;
    }
    return false;
  }
  createForm(cell) {
    var str = [
      { type: "settings", labelWidth: 150, inputWidth: 200 },
      {
        type: "radio",
        name: "memory_type",
        label: "servlet",
        checked: "1",
        value: "servlet",
        position: "label-right",
        list: [
          {
            type: "select",
            name: "shell_type",
            label: LANG["core"]["memory_shell"]["form"]["shell_type"],
            inputWidth: 200,
            options: [
              { value: "AntSwordServlet", text: "AntSword" },
              { value: "BehinderServlet", text: "Behinder" },
              { value: "GodzillaBase64Servlet", text: "Godzilla-Base64" },
              { value: "reGerogServlet", text: "reGerog" },
            ],
          },
          {
            type: "input",
            name: "ServiceName",
            label: LANG["core"]["memory_shell"]["form"]["ServiceName"],
            required: true,
          },
          {
            type: "input",
            name: "UrlPath",
            label: LANG["core"]["memory_shell"]["form"]["UrlPath"],
            required: true,
          },
          {
            type: "input",
            name: "ShellPass",
            label: LANG["core"]["memory_shell"]["form"]["ShellPass"],
            required: true,
          },
          {
            type: "input",
            name: "SecretKey",
            label: LANG["core"]["memory_shell"]["form"]["SecretKey"],
          },
        ],
      },
    ];
    var form = cell.attachForm(str);
    this.form = form;
  }
  getArgs() {
    let args = {};
    let memory_type = this.form.getCheckedValue("memory_type");
    if (memory_type == "servlet") {
      this.payloadtype = this.form.getItemValue("shell_type");
      args["UrlPath"] = this.form.getItemValue("UrlPath");
      args["ServiceName"] = this.form.getItemValue("ServiceName");
      switch (this.payloadtype) {
        case "BehinderServlet":
          args["ShellPass"] = this.form.getItemValue("ShellPass");
          break;
        case "GodzillaBase64Servlet":
          args["ShellPass"] = this.form.getItemValue("ShellPass");
          let crypto = require("crypto");
          let key = this.form.getItemValue("SecretKey");
          let SecretKey = crypto
            .createHash("md5")
            .update(key)
            .digest("hex")
            .substr(0, 16); //哥斯拉的key是明文md5处理后前16位
          args["SecretKey"] = SecretKey;
          break;
        case "reGerogServlet":
          break;
        case "AntSwordServlet":
          args["ShellPass"] = this.form.getItemValue("ShellPass");
        default:
          break;
      }
    }

    console.log(args);

    return args;
  }
}

module.exports = MemoryShell;
